<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Orders extends Backend {

	public function __construct()
	{
		parent::__construct();
		$this->lang->load('sites');
        $this->load->model(['site_model','paypal/account_model','paypal/summary_model','paypal/orders_model']);
		$this->data['page_home']  = lang('lang_dashboard');
		$this->data['page_title'] = lang('lang_order');
		
		$this->data['status']=[
			"1"=>'未付款',
			"2"=>'待确认',
			"3"=>'已付款',		
		];
		$this->data['statuslabel']=[
			"1"=>'label-danger',
			"2"=>'label-warning',
			"3"=>'label-success',
		];

    }


    public function index()
	{
		
		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			'贝宝订单'=>'backend/paypal/orders'
		);
		$key=trim($this->input->get('keyword'));
		if(substr($key, -1)==">")
		{
			$key=substr($key,0,-1);
		}
		
		$page=max(1,(int) $this->input->get('page'));
		$siteid=intval($this->input->get('siteid'));
		$pagesize=intval($this->input->get('pagesize'));		
		$timelimit=$this->input->get("timelimit");

        if($pagesize){
            set_cookie("pagesize",$pagesize,60*60*24);
        }else{
            $pagesize=get_cookie("pagesize");
		}
		$this->data['sindex']=$this->site_model->get_name_index();
		

		$state=(int) $this->input->get('state');
        
        $paypalmap=[];
        $payapls=$this->account_model->getall();
        if($payapls)
        {
            foreach($payapls as $p)
            {
                $paypalmap[$p["id"]]=$p;
            }
        }
        $this->data['paypalmap']=$paypalmap;


		$page_data=$this->orders_model->getpage($siteid,$page,$pagesize,$key,$state,$timelimit);
		$this->data['loglist']=$page_data["data"];
		$this->data['pager']=$page_data["pager"]; 
		$this->data['total']=$page_data["total"];
        $this->data['pages']=$page_data["pages"];
		$this->data['page']=$page;   
		$this->data['state']=$state;   
		$keyword = array(
			'name'      => 'keyword',
			'id'        => 'keyword',
			'value'     =>  $key,
			'class'     =>  'form-control input-sm',
			'placeholder'=> '请输入关键字',
			'maxlength' => '100'
		);
		$this->data['keyword']=$keyword;
		
		$this->data['content_header_title'] = content_header_title($this->data['page_title'],'订单');
		$this->data['content'] = 'paypal/orders';

		$this->render();
	}


}
